package com.yongjie.springbootlogin.controller;


import com.yongjie.springbootlogin.entity.PesonInfo;
import com.yongjie.springbootlogin.service.PesonInfoService;
import com.yongjie.springbootlogin.utils.ResultMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * 个人信息
 */
@Controller
public class PesonInfoController {
    @Autowired
    PesonInfoService pesonInfoService;

    @RequestMapping("/pesonInfo")
    public String staffinforpage (Map<String ,Object> map
            , HttpSession session
    ) throws  Exception{
        //获取session的id,查询医生信息
        String userID = (String) session.getAttribute("userID");
        PesonInfo userinfo= pesonInfoService.userinfo(userID);
        session.setAttribute("dname",userinfo.getDname());
        map.put("userinfo",userinfo);
        return "PesonInfo/PesonInfo";
}

    /**
     * 跳转到修改页
     * */
    @RequestMapping("/updatePersonInfo")
    public String upadtePersonInfo(Map<String ,Object> map
            , HttpSession session,HttpServletRequest request) {
        //获取session的id,查询医生信息
        String userID = (String) session.getAttribute("userID");
        PesonInfo userinfo= pesonInfoService.userinfo(userID);
        session.setAttribute("id",userinfo.getId());
        map.put("userinfo",userinfo);
        return "PesonInfo/updatePersonInfo";
    }

    /**
     * 修改个人信息
     * @param
     * @return 返回信息显示页
     */

    @RequestMapping("/upduserinfo")
    @ResponseBody
    public ResultMessage upduserinfo (PesonInfo pesonInfo){
        ResultMessage resultMessage=null;
        //更新数据
        int count = pesonInfoService.upduserinfo(pesonInfo);
        if(count>0){
            resultMessage=new ResultMessage(200,"更新成功");
        }else{
            resultMessage=new ResultMessage(500,"更新失败");
        }
        return resultMessage;
    }
}
